00001
00002 OtherPhysicalObjects::OtherPhysicalObjects(TraffEduObject* _object,char typeOfGeom,float length_lenght,float width_radius ,float height){
00003 if(typeOfGeom=='C' || typeOfGeom=='c'){
00004 geomType="cylinder";
00005 cylinderGeom.length=length_lenght;
00006 cylinderGeom.radius=width_radius;
00007 }
00008 else{
00009 geomType="prism";
00010 prismGeom.length=length_lenght;
00011 prismGeom.width=width_radius;
00012 prismGeom.height=height;
00013 }
00014 object=_object;
00015 this->root=root;
00016
00017 }
00018 OtherPhysicalObjects::~OtherPhysicalObjects(){
00019
00020 }
00021 OtherPhysicalObjects::OtherPhysicalObjects(TraffEduObject* object){
00022
00023 }
00024 int OtherPhysicalObjects::create(osg::ref_ptr<osg::PositionAttitudeTransform> objectPAT){
00025 if (_world == 0 || _space == 0)
00026 return false;
00027 if(geomType=="cylinder"){
00028
00029 geomID = dCreateCCylinder (_space,cylinderGeom.radius,cylinderGeom.length);
00030 }
00031 else{
00032 geomID = dCreateBox (_space,prismGeom.length,prismGeom.width, prismGeom.height);
00033
00034 }
00035
00036 osg::Quat quat =objectPAT->getAttitude();
00037 dReal* odeQuat= new dReal[4];
00038 odeQuat[0]=quat[1];
00039 odeQuat[1]=quat[2];
00040 odeQuat[2]=quat[3];
00041 odeQuat[3]=quat[0];
00042 dGeomSetQuaternion(geomID, odeQuat);
00043
00044 osg::Vec3d position=objectPAT->getPosition();
00045 dGeomSetPosition(geomID,position[0],position[1],position[2]);
00046
00047
00048
00049
00050 return 1;
00051
00052 }
00053 double OtherPhysicalObjects::update(double step){
00054 if(object->getObjectType()==VEHICLE)
00055 {
00056 osg::Quat vehicleQuat;
00057 vehicleQuat =object->getObjectPAT()->getAttitude();
00058 dReal* odeQuat= new dReal[4];
00059 odeQuat[0]=vehicleQuat[1];
00060 odeQuat[1]=vehicleQuat[2];
00061 odeQuat[2]=vehicleQuat[3];
00062 odeQuat[3]=vehicleQuat[0];
00063 dGeomSetQuaternion(geomID, odeQuat);
00064 osg::Vec3d position=object->getObjectPAT()->getPosition();
00065 dGeomSetPosition(geomID,position[0],position[1],position[2]);
00066 }
00067 return 1;
00068 }
00069
00070 void OtherPhysicalObjects::odeDraw(){
00071 ;
00072 }
00073
00074 void OtherPhysicalObjects::setCollusion()
00075 {
00076 object->getObjectPAT()->setUpdateCallback(0);
00077 }